﻿/*  -------------------------------------------------
    This file is part of the SchoolTube Live Platform
    Copyright © 2009 SchoolTube, LLC
    
    Licensed under the GNU General Public License v3
    http://www.gnu.org/licenses/gpl.html
    
    http://code.google.com/p/schooltubelive/
    ------------------------------------------------- */

import mx.events.DynamicEvent;

public var gigyaCfg:Object = { };

public function WFInit():void{
    Security.allowDomain("cdn.gigya.com");
    Security.allowInsecureDomain("cdn.gigya.com");
    
    if(wfLoaderBox.numChildren > 0 ){
        wfLoaderBox.visible = true;
        return;
    }


// configure wildfire
gigyaCfg['width']='250';
gigyaCfg['height']='250';
gigyaCfg['advancedTracking']='true';
gigyaCfg['partner']='248051';
gigyaCfg['UIConfig']='<config><display showDesktop="true" showEmail="true" useTransitions="true" showBookmark="true" codeBoxHeight="auto" showCloseButton="true"></display><body><background frame-color="#BFBFBF" background-color="#FFFFFF" gradient-color-begin="#ffffff" gradient-color-end="#F4F4F4" corner-roundness="13;13;13;13"></background><controls color="#202020" corner-roundness="4;4;4;4" gradient-color-begin="#EAEAEA" gradient-color-end="#F4F4F4" bold="false"><snbuttons iconsOnly="true" type="textUnder" frame-color="#D5D5D5" background-color="#fafafa" over-frame-color="#60BFFF" over-background-color="#ebebeb" color="#808080" gradient-color-begin="#FFFFFF" gradient-color-end="d4d6d7" size="10" bold="false" down-frame-color="#60BFFF" down-gradient-color-begin="#6DDADA" over-gradient-color-end="#6DDADA" down-gradient-color-end="#F4F4F4" over-color="#52A4DA" down-color="#52A4DA" over-bold="false"><more frame-color="#A4DBFF" over-frame-color="#A4DBFF" gradient-color-begin="#F4F4F4" gradient-color-end="#BBE4FF" over-gradient-color-begin="#A4DBFF" over-gradient-color-end="#F4F4F4"></more><previous frame-color="#BBE4FF" over-frame-color="#A4DBFF" gradient-color-begin="#FFFFFF" gradient-color-end="#A4DBFF" over-gradient-color-begin="#A4DBFF" over-gradient-color-end="#F4F4F4"></previous></snbuttons><textboxes frame-color="#CACACA" color="#757575" gradient-color-begin="#ffffff" bold="false"><codeboxes color="#757575" frame-color="#DFDFDF" background-color="#FFFFFF" gradient-color-begin="#ffffff" gradient-color-end="#FFFFFF" size="10"></codeboxes><inputs frame-color="#CACACA" color="#757575" gradient-color-begin="#F4F4F4" gradient-color-end="#ffffff"></inputs><dropdowns list-item-over-color="#52A4DA" frame-color="#CACACA"></dropdowns></textboxes><buttons frame-color="#CACACA" gradient-color-begin="#F4F4F4" gradient-color-end="#CACACA" color="#000000" bold="false" over-frame-color="#60BFFF" over-gradient-color-begin="#BBE4FF" down-gradient-color-begin="#BBE4FF" over-gradient-color-end="#FFFFFF" down-gradient-color-end="#ffffff"><post-buttons frame-color="#CACACA" gradient-color-end="#CACACA"></post-buttons></buttons><listboxes frame-color="#CACACA" corner-roundness="4;4;4;4" gradient-color-begin="#F4F4F4" gradient-color-end="#FFFFFF"></listboxes><checkboxes checkmark-color="#00B600" frame-color="#D5D5D5" corner-roundness="3;3;3;3" gradient-color-begin="#F4F4F4" gradient-color-end="#FFFFFF"></checkboxes><servicemarker gradient-color-begin="#ffffff" gradient-color-end="#D5D5D5"></servicemarker><tooltips color="#6D5128" gradient-color-begin="#FFFFFF" gradient-color-end="#FFE4BB" size="10" frame-color="#FFDBA4"></tooltips></controls><texts color="#202020"><headers color="#202020"></headers><messages color="#202020"></messages><links color="#52A4DA" underline="false" over-color="#353535" down-color="#353535" down-bold="false"></links></texts></body></config>';

    // Please set up the content to be posted
    gigyaCfg['defaultContent']= '<object width="420" height="375"><param name="movie" value="http://www.schooltube.com/l/'
    							+ currentStream + '" /><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" />'
    							+ '<embed src="http://www.schooltube.com/l/'
    							+ currentStream + '" type="application/x-shockwave-flash" allowFullScreen="true" allowscriptaccess="always" width="420" height="375"></embed></object>';
    
    
    // set up an event handler for the onClose event, this is called when the Wildfire UI is closed.
    gigyaCfg['onClose']=function(eventObj:Object):void{
        //add here code to hide
        wfLoaderBox.visible = false;
        MovieClip(Loader(mx.core.UIComponent(wfLoaderBox.getChildAt(0)).getChildAt(0)).content).INIT();
    }
    
    var wfLoader:flash.display.Loader;
    wfLoader=new flash.display.Loader();

    if (wfLoaderBox.numChildren == 0 ) {
     wfLoader.contentLoaderInfo.sharedEvents.addEventListener("sendConfig",
      function(e:Event):void{
       var evtObj:mx.events.DynamicEvent=new mx.events.DynamicEvent('onStoreConfig');
       evtObj.cfg=gigyaCfg;
       wfLoader.contentLoaderInfo.sharedEvents.dispatchEvent(evtObj);
      }
     )
     wfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,
      function(event:Event):void{
       var uic:mx.core.UIComponent = new mx.core.UIComponent();
       wfLoaderBox.addChild(uic);
       uic.addChild(wfLoader);
       btnGigya.enabled = true;
       btnGigya.useHandCursor = true;
      });
 
        // Load Wildfire
        wfLoader.load(new URLRequest('http://cdn.gigya.com/wildfire/swf/wildfireInAS3.swf?ModuleID=cfg'));
        
    }
    else {
     MovieClip(Loader(mx.core.UIComponent(wfLoaderBox.getChildAt(0)).getChildAt(0)).content).INIT();
    }
    

}